<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('训练成绩录入')"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="data-form">
                <input id="scheduleTime" name="scheduleTime" type="hidden" th:value="${scheduleTime}">
                <div class="panel blank-panel">

                    <div class="panel-heading">
                        <div class="panel-options">

                            <ul class="nav nav-tabs" th:each="studentBasics: ${studentBasicsVO}">

                                <li class=""><a class="btn btn-default btn-rounded" th:onclick="|studentEntering(${studentBasics.studentId})|">
                                    <i th:text="${studentBasics.studentName}"></i></a>
                                </li>

                            </ul>
                        </div>
                    </div>

                    <div class="panel-body">
                        <div class="tab-content">
                            <div id="tab" class="tab-pane active">

                            </div>
                        </div>
                    </div>

                </div>

            </form>
        </div>

        <div class="row">
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭</button>
            </div>
        </div>
    </div>
</div>



<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">

    var prefix = ctx + "business/scheduleRecord";

    var gradeType = [[${@dict.getType('business_grade_type')}]];

    // 切换小孩展示该小孩的课程评分
    function studentEntering(studentId) {
        var formData = new FormData();
        formData.set("scheduleTime", $('#scheduleTime').val());
        formData.set("studentId", studentId);
        $.ajax({
            url: prefix + '/entering',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    var $tab = $("#tab");
                    $tab.html("");
                    if (result.data != null) {
                        for (var i = 0; i < result.data.length; i++) {
                            $tab.append("<div><p>" + result.data[i].questionNum + "." + result.data[i].questionName + "</p>" +
                                "<input name='list["+ i +"].questionNum' type='hidden' value='"+ result.data[i].questionNum +"'>" +
                                "<input name='list["+ i +"].questionType' type='hidden' value='"+ result.data[i].questionType +"'>" +
                                "<input name='list["+ i +"].studentId' type='hidden' value='"+ result.data[i].studentId +"'>" +
                                "<input name='list["+ i +"].teacherId' type='hidden' value='"+ result.data[i].teacherId +"'>" +
                                "<input name='list["+ i +"].centerId' type='hidden' value='"+ result.data[i].centerId +"'>");
                            if (result.data[i].grade == null) {
                                if (result.data[i].inputType == 1) {
                                    $tab.append("<p>时间（分）: &nbsp;&nbsp;&nbsp;<input name='list["+ i +"].totalNum' type='number' placeholder='只能输入正整数'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时间（秒）：<input name='list["+ i +"].completeNum'  type='number' placeholder='只能输入正整数'/></p>");
                                } else {
                                    $tab.append("<p>总尝试回合： &nbsp;&nbsp;&nbsp;<input name='list["+ i +"].totalNum' type='number' placeholder='只能输入正整数'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;总达成回合：<input name='list["+ i +"].completeNum'  type='number' placeholder='只能输入正整数'/></p>");
                                }
                            } else {
                                $tab.append("<p>总尝试回合： &nbsp;&nbsp;&nbsp;"+ $.table.selectDictLabel(gradeType, result.data[i].grade) +"</p></div>");
                            }
                        }
                    }
                }
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            var data = $('#data-form').serializeArray();
            $.operate.save(prefix + "/saveEntering", data);
        }
    }


</script>
</body>

</html>